package com.sharding.utils;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Desc:
 * Date:    2023/2/27
 *
 * @author WanYangWei
 */
public class DateTimeUtils {
    /**
     *  yyyy-MM-dd
     * @return
     */
    public static String getDateStr(){
        DateFormat dateInstance = SimpleDateFormat.getDateInstance();
        return dateInstance.format(new Date());
    }

    public static String getDateTimeStr(){
        SimpleDateFormat dateInstance = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateInstance.format(new Date());
    }

    /**
     *
     * @param dateTimeStr
     * @return
     * @throws Exception
     */
    public static Date parseDateTimeStr(String dateTimeStr) throws Exception{
        SimpleDateFormat dateInstance = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateInstance.parse(dateTimeStr);
    }

    /**
     *
     * @param timestamp
     * @return
     * @throws Exception
     */
    public static String formatTimestamp(Timestamp timestamp) throws Exception{
        SimpleDateFormat dateInstance = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateInstance.format(timestamp);
    }
}
